<?php
class Kid{
	public function addKid($name,$parent_id,$class_id,$age,$height='',$weight='',$avatar=''){
		$sql = "INSERT INTO `kid` VALUES (:id,:parent_id,:class_id,:name,:height,:weight,:age,:avatar)";
		$field = array(':id' => '',
					   ':parent_id' => $parent_id,
					   ':class_id' => $class_id,
					   ':name' => $name,
					   ':height' => $height,
					   ':weight' => $weight,
					   ':age' => $age,
					   ':avatar' => $avatar
					  );

		return DB::updateDB($sql,$field);			  
	}
	
	public function editKid($id,$name,$parent_id,$class_id,$age,$height='',$weight='',$avatar=''){
		$sql = "UPDATE kid set name=?,parent_id=?,class_id=?,age=?,height=?,weight=?,avatar=? where id='$id'";
		$field = array($name,$parent_id,$class_id,$age,$height,$weight,$avatar);
		return DB::updateDB($sql,$field);
	}
	
	public function delKid($id){
		global $db;
		$sql = "delete from kid where id='$id'";
		return $db->query($sql);
		
	}
	
	
	public function getKid(){
		$DB = new DB();
		$sql = "SELECT
				k.id,k.name,k.age,c.title as class,u.username,g.title as grade 
				FROM
				kid k, class c, user u,grade g
				WHERE 
				k.class_id = c.id 
				AND
				k.parent_id=u.id
				AND
				c.grade_id = g.id";
		
		return $DB->fetchAll($sql);
	}
	
	public function getOne($id){
		$sql = "SELECT
				k.*,u.id as parent,c.id as class,g.id as grade
			    FROM
				kid k, class c,user u,grade g
				WHERE
				k.id = '$id'
				AND 
				k.class_id = c.id
				AND
				k.parent_id = u.id
				AND
				c.grade_id = g.id";
		return DB::fetchRow($sql);			
	}
	
	public function getKidByParent($id){
		$sql = "SELECT * from kid where parent_id = '$id'";
		return DB::fetchRow($sql);	
	}
	
	public function getKidByClass($id){
		$sql = "SELECT *
				FROM kid k
				WHERE 
				k.class_id = '$id'

				";
		return DB::fetchAll($sql);	
	}
}
?>